<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="box">
        <h1 ref='title'>this is a title</h1>
        <button @click='getRef'>获取ref</button>
        <my-child ref='mychild'></my-child>
    </div>
    <script>
        Vue.component("myChild", {
            template: `
            <div>this is myChild component</div>
            `,
            data() {
                return {
                    str: 'hhh哈'
                }
            },
            methods: {

            }
        })
        var vm = new Vue({
            el: "#box",
            data: {
                pMsg: '父组件传递的状态'
            },
            methods: {
                getRef() {
                    console.log(this.$refs.mychild.str)
                }
            }
        })
    </script>
</body>

</html>